﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using VAdvantage.Utility;

namespace Desktop
{
    public partial class YTSearch : UserControl
    {

        public event RoutedEventHandler Click = null;

        public YTSearch()
        {
            InitializeComponent();
            SetControlTextAndData();
        }

        private void SetControlTextAndData()
        {
            tbSeach.Text = Msg.GetMsg("Search");
            tbPageSize.Text = Msg.GetMsg("Page");
            tbLang.Text = Msg.GetMsg("language");
            tbOrder.Text = Msg.GetMsg("Order");
            btnSearch.Content = Msg.GetMsg("Search");

            List<String> orderList = new List<string>(4);
            orderList.Add(Msg.GetMsg("Relevance"));
            orderList.Add(Msg.GetMsg("Published"));
            orderList.Add(Msg.GetMsg("ViewCount"));
            orderList.Add(Msg.GetMsg("Rating"));

            cmbOrder.ItemsSource = orderList;
            cmbOrder.SelectedIndex = 1;

            for (int i = 5; i < 55; i+=5)
            {
                cmbPage.Items.Add(i.ToString());
            }

            cmbPage.SelectedIndex = 1;

            btnSearch.Click += new RoutedEventHandler(btnSearch_Click);

            hLink.Click += new RoutedEventHandler(hLink_Click);

        }

        void hLink_Click(object sender, RoutedEventArgs e)
        {
            Envs.StartBrowser("http://www.loc.gov/standards/iso639-2/php/code_list.php");
        }

        void btnSearch_Click(object sender, RoutedEventArgs e)
        {
            if (Click != null)
            {
                Click(this, e);
            }
        }

        public String GetOrderBy
        {
            get
            {
                if (cmbOrder.SelectedIndex < 0 || cmbOrder.Items.Count == 0)
                {
                    return "published";
                }

                if (cmbOrder.SelectedIndex == 0)
                {
                    return "relevance";
                }
                if (cmbOrder.SelectedIndex == 1)
                {
                    return "published";
                }
                if (cmbOrder.SelectedIndex == 2)
                {
                    return "viewCount";
                }
                else
                {
                    return "rating";
                }
            }
        }

        public String GetLang
        {
            get
            {
                if (string.IsNullOrEmpty(txtLang.Text))
                    return "en";
                return txtLang.Text;
            }
        }

        public int GetPageSize
        {
            get
            {
                if (cmbPage.SelectedItem != null)
                {
                  return Convert.ToInt32(cmbPage.SelectedItem.ToString());
                }
                else
                    return 10;
            }
        }

        public string GetSearchText
        {

            get
            {
                return txtSearch.Text;
            }
        }
    }
}
